﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Text;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using PlugNT.Cms.Core;
using PlugNT.Cms.Model;
using PlugNT.Cms.BLL;
using PlugNT.Cms.Page;
using FJASPX.Service;
using FJASPX.Domain;

namespace PlugNT.Cms.Web.Admin.Pre_Trade
{

    public partial class Admin : AdminPage
    {
        public ITradeService iTradeService { get; set; }

        protected string classType
        {
            get
            {
                return ViewState["clstype"].ToString();
            }
            set
            {
                ViewState["clstype"] = value;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            //权限检测
            this.CheckPower();
            if (!IsPostBack)
            {
                BindData();
            }
        }

        #region 数据绑定
        private void BindData()
        {
            this.rptMenuList.DataSource = iTradeService.GetAll();
            this.rptMenuList.DataBind();
        }
        #endregion

        #region 显示数据处理
        protected void rptMenuList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                Literal LitFirst = (Literal)e.Item.FindControl("LitFirst");
                Label LabClassNm = (Label)e.Item.FindControl("LabClassName");

                string LitStyle = "<span style=\"width:{0}px; text-align:right; vertical-align:middle; line-height:25px; height:25px;\">{1}{2}</span>";
                string LitImg1 = "<img src=../images/openfolder.gif align=absmiddle />";
                string LitImg2 = "<img src=../images/folder.gif align=absmiddle />";
                string LitImg3 = "<img src=../images/t.gif align=absmiddle />";
                Trade trade = (Trade)e.Item.DataItem;
                int clsListLen = Convert.ToInt32(trade.ParentId);

                if (clsListLen == 0)
                {
                    LabClassNm.Font.Bold = true;
                    LitFirst.Text = LitImg1;
                }
                else
                {
                    LitFirst.Text = string.Format(LitStyle, clsListLen * 20, LitImg3, LitImg2);
                }
            }
        }
        #endregion

        #region 编辑删除处理
        protected void rptMenuList_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            HiddenField hidClassId = (HiddenField)e.Item.FindControl("hidClassId");
            HiddenField hidClassTag = (HiddenField)e.Item.FindControl("hidClassTag");
            Label LabClassNm = (Label)e.Item.FindControl("LabClassName");
            try
            {
                switch (e.CommandName.ToLower())
                {
                    case "btndelete":
                        iTradeService.DeleteById(Int32.Parse(hidClassId.Value));
                        Page.ClientScript.RegisterStartupScript(Page.GetType(), "ajaxjs", "alert('所选行业删除成功！')", true);
                        BindData();
                        break;
                }

            }
            catch (Exception ex) { Page.ClientScript.RegisterStartupScript(Page.GetType(), "ajaxjs", string.Format("alert('删除操作失败，请与管理员联系！{0}')", ex), true); }
        }
        #endregion
    }
}
